//
//  EaseMedicineCell.m
//  HAZDoctor
//
//  Created by 李晓俊 on 2018/10/25.
//  Copyright © 2018年 李晓俊. All rights reserved.
//

#import "EaseMedicineCell.h"
#define cellHeight 163+15
#define bubbleViewHeight cellHeight - 15 // 气泡背景图高度
@implementation EaseMedicineCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}
#pragma mark - 系统回调
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier model:(id<IMessageModel>)model {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier model:model];
    if (self) {
         [self setupSubViewWithModel:model];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}
#pragma mark - 重写父类方法
/** 获取cell的reuseIdentifier */
+ (NSString *)cellIdentifierWithModel:(id<IMessageModel>)model {
    return @"EaseMedicineCell";
}
/** 获取cell高度 */
+ (CGFloat)cellHeightWithModel:(id<IMessageModel>)model
{
    return cellHeight;
}
/** 判断是否需要自定义气泡 */
- (BOOL)isCustomBubbleView:(id<IMessageModel>)model
{
    return YES;
}
/** 根据消息model变更气泡样式 */
- (void)setCustomModel:(id<IMessageModel>)model {
    UIImage *image = model.image;
//    if (!image) {
//        [self.bubbleView.imageView sd_setImageWithURL:[NSURL URLWithString:model.fileURLPath] placeholderImage:[UIImage imageNamed:@"icon_logo"]];
//     } else {
//        _bubbleView.imageView.image = image;
//     }
//    if (model.avatarURLPath) {
//        [self.avatarView sd_setImageWithURL:[NSURL URLWithString:model.avatarURLPath] placeholderImage:[UIImage imageNamed:@"icon_logo"]];
//     } else {
//         self.avatarView.image = model.avatarImage;
//     }
    self.bubbleView.imageView.hidden = YES;
    self.avatarView.hidden = YES;
 }
/** 根据消息改变气泡样式 */
- (void)setCustomBubbleView:(id)model{
    _bubbleView.imageView.image = [UIImage imageNamed:@"imageDownloadFail"];
}

/** 更新自定义气泡的边距 */
- (void)updateCustomBubbleViewMargin:(UIEdgeInsets)bubbleMargin model:(id<IMessageModel>)mode {
    _bubbleView.translatesAutoresizingMaskIntoConstraints = YES;
    CGFloat nameLabelHeight = 15;
    // 昵称label的高度
    if (mode.isSender) {
         _bubbleView.frame = CGRectMake(kScreenWidth/2.0-124, 0, 248, bubbleViewHeight);
        _bubbleView.backgroundColor = [UIColor clearColor];
//        self.tishiLabel.text = @"XX通过了你创建的卡牌";
        //关键语句
//        _bubbleView.layer.cornerRadius = 4.0;//2.0是圆角的弧度，根据需求自己更改
//        _bubbleView.layer.borderColor = KMineLine.CGColor;//设置边框颜色
//        _bubbleView.layer.borderWidth = 1.0f;//设置边框宽度
    }else{
        _bubbleView.frame = CGRectMake(kScreenWidth/2.0-124, 0,248, bubbleViewHeight);
        _bubbleView.backgroundColor = [UIColor clearColor];
        //关键语句
//        _bubbleView.layer.cornerRadius = 4.0;//2.0是圆角的弧度，根据需求自己更改
//        _bubbleView.layer.borderColor = KMineLine.CGColor;//设置边框颜色
//        _bubbleView.layer.borderWidth = 1.0f;//设置边框宽度
     }
 }
    
#pragma mark - 私有方法 /** 添加子控件 */
- (void)setupSubViewWithModel:(id<IMessageModel>)model {
    NSLog(@"扩展消息 === %@",model.message.ext);
    self.hasRead.hidden = YES;
    self.bubbleView.backgroundColor = [UIColor clearColor];
    [self.bubbleView.backgroundImageView addSubview:self.iconImgView];
    [self.bubbleView.backgroundImageView addSubview:self.tishiLabel];

 }
#pragma mark - lazy
- (UIImageView *)iconImgView {
    if (!_iconImgView) {
        _iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 248, 163)];
        _iconImgView.image = [UIImage imageNamed:@"Streakcover"];
    }
    return _iconImgView;
}

- (UILabel *)tishiLabel {
    if (!_tishiLabel) {
        _tishiLabel = [[UILabel alloc] initWithFrame:CGRectMake(48, 30, 140, 70)];
        _tishiLabel.font = CLRudeCircleTextFont(18);
        _tishiLabel.textAlignment = NSTextAlignmentCenter;
        _tishiLabel.textColor = KBlackColor;
        _tishiLabel.numberOfLines = 0;
    }
    return _tishiLabel;
}


@end
